/**
 * 
 */
package com.agrec.server;

import java.sql.SQLException;
import java.util.ArrayList;

import com.agrec.client.actors.CitiesNames;
import com.agrec.client.actors.CompaniesNames;
import com.agrec.client.actors.Name;
import com.agrec.client.actors.Position;
import com.agrec.client.services.KMRService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * @author allomeen
 *
 */
@SuppressWarnings("serial")
public class KMRServiceImpl extends RemoteServiceServlet implements KMRService {

	/**
	 * 
	 */
	public KMRServiceImpl() {
		DatabaseManager.instance();
	}

	public CompaniesNames getComapniesNames() {
		CompaniesNames names = new CompaniesNames(); //getCompaniesNames();
		names.add("Emmar");
		names.add("Unilever");
		names.add("KMR");
		names.add("Proctle & Gamble");
		names.add("NCB");
		
		return names;
	}

	public CitiesNames getCitiesNames(String country) {
		CitiesNames citiesNames = new CitiesNames();//getCitiesFor(country);
		
		if(country.equals("Saudi Arabia")){
			citiesNames.names.add("Jeddah");
			citiesNames.names.add("Jiddah");
			citiesNames.names.add("Sharqya");
			citiesNames.names.add("Ryiad");
			citiesNames.names.add("Makkah");
		}else{
			citiesNames.names.add("Dubai");
			citiesNames.names.add("Abu Dhabi");
			citiesNames.names.add("Sharja");
		}
		return citiesNames;
	}

	public Boolean addCandidate(Name candidate) {
		return DatabaseManager.addCandidate(candidate);
	}

	public ArrayList<Position> getRecentOpportunities(int numOfPos) {
		ArrayList<Position> pos = null;
//		Position p1 = new Position();
//		p1.id(10);
//		p1.city("Jeddah");
//		p1.jobTitle("Marketing Manager");
//		p1.userName("Tarik");
//		pos.add(p1);
//		pos.add(new Position());
		try {
			pos =  DatabaseManager.getRecentOpportunities(numOfPos);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return pos;
	}
}
